package com.xuebang.admin.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import com.xuebang.admin.entity.Operator;

public interface OperatorMapper extends BaseMapper<Operator> {
	
	@Select("select * from operators")
	List<Operator> search();

	@Select("select * from operators where OPERATOR_ID = #{operatorId}")
	Operator findById(Long operatorId);

	@Select("select * from operators where LOGIN_NAME = #{loginName} and status='A'")
	Operator findByLoginName(String loginName);

	@Insert("insert into operators (NAME,LOGIN_NAME,PASSWD,EMAIL,MOBILE,CREATE_DATE,POSITION_ID,status,GROUP_ID) VALUES "+
			"(#{name},#{loginName},#{passwd},#{email},#{mobile},#{createDate},#{positionId},#{status},#{groupId})")
	@SelectKey(statement = "select last_insert_id()", keyProperty = "operatorId", before = false, resultType = Long.class)
	void insertOperator(Operator operator);
	
	@Update("update operators set NAME = #{name},PASSWD = #{passwd},EMAIL = #{email},MOBILE = #{mobile},MODIFY_DATE = #{modifyDate},LAST_LOGIN_DATE = #{lastLoginDate}," +
			"POSITION_ID = #{positionId},status = #{status},GROUP_ID = #{groupId} where OPERATOR_ID = #{operatorId}")
	void updateOperator(Operator operator);
	
	@Update("update operators set NAME = #{name},EMAIL = #{email},MOBILE = #{mobile},MODIFY_DATE = #{modifyDate},LAST_LOGIN_DATE = #{lastLoginDate}," +
			"POSITION_ID = #{positionId},status = #{status},GROUP_ID = #{groupId} where OPERATOR_ID = #{operatorId}")
	void updateOperatorExceptPasswd(Operator operator);
	
	/*@Update("update operators set status = 'C', group_Id = NULL where operator_Id = #{operatorId}")*/
	@Delete("delete from operators where OPERATOR_ID = #{operatorId}")
	void delOperator(Long operatorId);
}
